package com.naizhuai.util;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;

import com.naizhuai.R;
import com.naizhuai.ui.entity.mainbusiness.ActionBaseBean;
import com.naizhuai.ui.entity.mainbusiness.ActionShowMainItemBean;
import com.naizhuai.ui.mianbusiness.action.ActionBeforeExamineDetailsActivity;
import com.naizhuai.ui.mianbusiness.action.ActionDetailTxtCreateActivity;
import com.naizhuai.ui.mianbusiness.action.ActionEditContrastActivity;
import com.naizhuai.ui.task.ActionSetting1Activity;

import java.io.Serializable;
import java.util.Map;

/**
 * 界面跳转工具类
 * Created by code_han on 2018/3/2.
 */

public class IntentUtils {
    /*
    是否为查看或者编辑模式
     */
    public static final String ENTER_ACTIVITY_TYPE_KEY = "enter_activity_type";
    //进入页面拿到的object
    public static final String INTENT_OBJECT = "intent_object";
    //浏览模式进入页面
    public static final int PREVIEW_FROM_SCAN = 20001;
    //编辑模式进入界面
    public static final int PREVIEW_FROM_EDIT = 20002;

    public static void startActivityWithString(String strKey, String[] params, Context mContext, Class actCls) {
        Intent intent = new Intent();
        Bundle bundle = new Bundle();
        bundle.putStringArray(strKey, params);
        intent.putExtras(bundle);
        intent.setClass(mContext, actCls);
        mContext.startActivity(intent);
    }

    public static <T extends Serializable> void startActivityWithObject(String strKey, T param, Context mContext, Class actCls) {
        Intent intent = new Intent();
        intent.putExtra(strKey, param);
        intent.setClass(mContext, actCls);
        mContext.startActivity(intent);
    }

    public static void startActivity(Context mContext, Class actCls) {
        Intent intent = new Intent();
        intent.setClass(mContext, actCls);
        mContext.startActivity(intent);
    }

    public static void startActivityWithString(String[] strKey, String[] params, Context mContext, Class actCls) {
        Intent intent = new Intent();
        Bundle bundle = new Bundle();
        for (int i = 0; i < strKey.length; i++)
            bundle.putString(strKey[i], params[i]);
        intent.putExtras(bundle);
        intent.setClass(mContext, actCls);
        mContext.startActivity(intent);
    }

    public static void startActivityWithString(String[] strKey, int[] params, Context mContext, Class actCls) {
        Intent intent = new Intent();
        Bundle bundle = new Bundle();
        for (int i = 0; i < strKey.length; i++)
            bundle.putInt(strKey[i], params[i]);
        intent.putExtras(bundle);
        intent.setClass(mContext, actCls);
        mContext.startActivity(intent);
    }

    public static void startActivityWithStringAndInt(String[] strKey, String[] strValue, String[] intKey, int[] intValue, Context mContext, Class actCls) {
        Intent intent = new Intent();
        Bundle bundle = new Bundle();
        for (int i = 0; i < strKey.length; i++)
            bundle.putString(strKey[i], strValue[i]);
        for (int i = 0; i < intKey.length; i++)
            bundle.putInt(intKey[i], intValue[i]);
        intent.putExtras(bundle);
        intent.setClass(mContext, actCls);
        mContext.startActivity(intent);
    }

    public static void startActivityWithStringForResult(String[] strKey, int[] params, Activity mContext, Class actCls, int code) {
        Intent intent = new Intent();
        Bundle bundle = new Bundle();
        for (int i = 0; i < strKey.length; i++)
            bundle.putInt(strKey[i], params[i]);
        intent.putExtras(bundle);
        intent.setClass(mContext, actCls);
        mContext.startActivityForResult(intent, code);
    }


    public static <T extends Serializable> void startActivityWithObjectForResult(String strKey, T param, Activity mContext, Class actCls, int code) {
        Intent intent = new Intent();
        intent.putExtra(strKey, param);
        intent.setClass(mContext, actCls);
        mContext.startActivityForResult(intent, code);
    }

    public static <T extends Serializable> void startActivityWithObjectAndStringForResult(String strKey, T param, String key, String value, Activity mContext, Class actCls, int code) {
        Intent intent = new Intent();
        intent.putExtra(strKey, param);
        intent.putExtra(key, value);
        intent.setClass(mContext, actCls);
        mContext.startActivityForResult(intent, code);
    }

    public static void startActivityWithStringForResult(String[] strKey, String[] params, Activity mContext, Class actCls, int code) {
        Intent intent = new Intent();
        Bundle bundle = new Bundle();
        for (int i = 0; i < strKey.length; i++)
            bundle.putString(strKey[i], params[i]);
        intent.putExtras(bundle);
        intent.setClass(mContext, actCls);
        mContext.startActivityForResult(intent, code);
    }

    public static void startActivityWithMutiForResult(String[] param1, String key2, int value2, Activity mContext, Class actCls, int code) {
        Intent intent = new Intent();
        Bundle bundle = new Bundle();
        bundle.putString(param1[0], param1[1]);
        bundle.putInt(key2, value2);
        intent.putExtras(bundle);
        intent.setClass(mContext, actCls);
        mContext.startActivityForResult(intent, code);
    }

    public static void startActivityForResult(Activity mContext, Class actCls, int code) {
        Intent intent = new Intent();
        intent.setClass(mContext, actCls);
        mContext.startActivityForResult(intent, code);
    }

    public static void startActivityWithInteger(String strKey, int params, Context mContext, Class actCls) {
        Intent intent = new Intent();
        Bundle bundle = new Bundle();
        bundle.putInt(strKey, params);
        intent.putExtras(bundle);
        intent.setClass(mContext, actCls);
        mContext.startActivity(intent);
    }

    public static void startActivityWithString(String strKey, String params, Context mContext, Class actCls) {
        Intent intent = new Intent();
        Bundle bundle = new Bundle();
        bundle.putString(strKey, params);
        intent.putExtras(bundle);
        intent.setClass(mContext, actCls);
        mContext.startActivity(intent);
    }

    //根据行为不同的步骤跳转不同的界面
    public static void startStepActivity(String step, String actionId, Context mContext) {
        switch (step) {
            case ActionShowMainItemBean.STEP_1:
                startActivityWithString(ActionBaseBean.ACTION_ID_KEY, actionId, mContext, ActionSetting1Activity.class);
                break;
            case ActionShowMainItemBean.STEP_2:
                startActivityWithString(ActionBaseBean.ACTION_ID_KEY, actionId, mContext, ActionDetailTxtCreateActivity.class);
                break;
            case ActionShowMainItemBean.STEP_3:
                startActivityWithString(ActionBaseBean.ACTION_ID_KEY, actionId, mContext, ActionEditContrastActivity.class);
                break;
            case ActionShowMainItemBean.STEP_4:
//                DialogUtils.showPromptDialog(mContext, mContext.getString(R.string.action_be_examine));
                startActivityWithString(ActionBaseBean.ACTION_ID_KEY, actionId, mContext, ActionBeforeExamineDetailsActivity.class);
                break;
        }

    }

}
